import common from "../../../utils/public.js"
const app = getApp();
Page({
  data: {
    title: null,
    body: null
  },
  inputTitle(e) {
    this.setData({
      title: e.detail.value
    })
  },
  inputBody(e) {
    this.setData({
      body: e.detail.value
    })
  },
  back(e) {
    wx.navigateBack({
      delta: 1,
    })
  },
  saveData() {
    var that = this;
    wx.request({
      url: 'http://localhost:8080/clock_war_exploded/managerNotice/save',
      method: "POST",
      data: {
        title: this.data.title,
        body: this.data.body
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded;charset=utf-8'
      },
      success: function (res) {
        if (res.data) {
          wx.showToast({
            title: '发布成功',
            icon: 'success',
          })
          that.getRequest()
        }
      },
    })
    
  },
  getRequest: function () {
    var that = this;
    wx.request({
      url: 'http://localhost:8080/clock_war_exploded/managerNotice/findAll',
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded;charset=utf-8'
      },
      success: function (res) {
        if (res.data != null) {
          res.data.forEach(item => {
            item.date = common.getMyDate(item.date)
            item.body = common.getStrLen(item.body, 35)
          })
          that.setData({
            noticeList: res.data
          })
        } else {}
      }
    })
  },

  onLoad: function () {
    this.getRequest()
  }

})